//! API网关模块

pub mod server;
pub mod handlers;
pub mod middleware;

pub use server::*;
pub use handlers::*;
pub use middleware::*;

#[cfg(test)]
mod tests {
    use super::*;
    use std::sync::Arc;
    use data_gateway_kernel::DataGatewayKernel;

    #[tokio::test]
    async fn test_http_server_creation() {
        let kernel = Arc::new(DataGatewayKernel::new().await.unwrap());
        let server = HttpServer::with_default_config(kernel);

        // 测试路由创建
        let _router = server.create_router();
        // 简单验证服务器创建成功
        assert_eq!(server.config.port, 8080);
    }

    #[test]
    fn test_http_server_config_default() {
        let config = HttpServerConfig::default();
        assert_eq!(config.host, "0.0.0.0");
        assert_eq!(config.port, 8080);
        assert!(config.enable_cors);
        assert_eq!(config.request_timeout_seconds, 30);
    }

    #[test]
    fn test_query_request_deserialization() {
        let json = r#"
        {
            "query_type": "sql",
            "query": "SELECT * FROM users",
            "params": {"limit": 10}
        }
        "#;

        let request: QueryRequest = serde_json::from_str(json).unwrap();
        assert_eq!(request.query_type, "sql");
        assert_eq!(request.query, "SELECT * FROM users");
        assert!(request.params.is_some());
    }
}
